<script src="jquery-3.2.1.min.js"></script>
<h1>数据上屏，内容推送服务</h1>
<div class="table_box">
	免费零代码/低代码数据可视化平台<br>
	轻松实现数据可视化报表 / 大屏、数据门户、物联网云组态，降低成本，创造利润。<br>
	免费下载使用：<a href="http://www.chudayun.com" target="_blank">http://www.chudayun.com</a>
</div>
<div class="table_box" style="margin-top: 15px;">
	推送步骤：
	<p>1,先选择设备
		<br>
		2,填写数据
		<br>
		3,点击推送
	</p>
	<select id="deviceList" name="deviceid" style="width: 80%"></select>
	<br><br>
	<textarea name="contentData" id="contentData" style="width: 80%" rows="10">[{
	"url": "http://www.chudayun.com",
	"duration": 5,
	"id": "1001"
},{
	"url": "http://demo.datav.hezyun.cn/chudy_visual/view/1539916447218663424",
	"duration": 5,
	"id": "1539916447218663424"
},{
	"url": "http://demo.datav.hezyun.cn/chudy_visual/view/1580439656195948544",
	"duration": 5,
	"id": "1580439656195948544"
}]</textarea>
<br>参数说明：<br>
	<table style="width: 80%;border-color: #fff;border-spacing: 0px" cellpadding="0" border="1">
		<tr><td style="width: 100px">url</td><td>看板url地址</td></tr>
		<tr><td>duration</td><td>播放时长（单位：秒）</td></tr>
		<tr><td>id</td><td>看板id，唯一标识</td></tr>
	</table>
	<br>
	<input type="text" id="apptoken" placeholder="请输入 app token" name="token" style="width: 80%;"/>
	<br/><br/>
	<input type="button" onclick="submitData()" value="推送" style="width: 120px;">
	<br/><br/>

</div>
<script>
	$.ajax({
		type: 'POST',
		url: "/client/devicelist",
		data: {},
		success: function(res){

			$.each(res.data,function(index,item){
				// console.log(item);
				var label = "设备ID：" + item.deviceid + ",设备IP："  + item.deviceip;
				$("<option value="+item.deviceid+">"+ label +"</option>").appendTo("#deviceList");
			});
		},
		dataType: "json"
	});
	function submitData(){
		// console.log($("#contentData").val());
		$.ajax({
			type: 'POST',
			contentType: "application/json; charset=utf-8",
			url: "/push?deviceid=" + $("#deviceList").val() +"&token=" + $("#apptoken").val(),
			data: $("#contentData").val(),
			success: function(res){
				if(res.code == '0'){
					alert("推送完成");
				}else{
					alert(res.msg);
				}
				
			},
			dataType: "json",
			error:function(error){
				alert("推送异常:" + error.message);
			}
		});
	}
</script>
